package jvs.vfs.opt.contact;

import jvs.vfs.opt.ItemInfo;

public class ContactInfo extends ItemInfo {
	public static final int STAR_SUPER = 2;
	public static final int STAR_ONE = 1;
	public static final int STAR_NO = 0;

	public static final int TYPE_CUSTOM = 0;
	public static final int TYPE_HOME = 1;
	public static final int TYPE_WORK = 2;
	public static final int TYPE_MOBILE = 3;
	public static final int TYPE_OTHER = 4;

	private static final int STAR_MAX = 2; // 0 no, 1 one, 2 super
	
	public String[] emails;
	public long cid;
	// public long id; //1.5 contact id, 2.0 raw id
	public long lastTime;
	public String name;
	public int starred;
	public int times;
	//
	public String phone;
	public int phoneType;
	public String phoneLabel;
	public String address;
	
	public String phoneticName;

	public ContactInfo() {
	}

	/**
	 * Guard against index out of bound
	 * 
	 * @return
	 */
	public int getStarred() {
		int s = starred;
		s = (s < 0 ? 0 : s);
		s = (s > STAR_MAX ? STAR_MAX : s);
		return s;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	/**
	 * @return true if names are identical
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		ContactInfo other = (ContactInfo) obj;
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(sortkey);
		sb.append("|");
		sb.append(cid);
		sb.append("|");
		sb.append(id);
		sb.append("|");
		sb.append(starred);
		sb.append("|");
		sb.append(name);
		sb.append("|");
		sb.append(lastTime);
		sb.append("|");
		sb.append(times);
		sb.append("|");
		if (emails != null && emails.length > 0) {
			for (int i = 0; i < emails.length; i++) {
				sb.append(emails[i]);
				sb.append(",");
			}
		}
		sb.append("|");
		sb.append(phoneLabel);
		sb.append("|");
		sb.append(phoneType);
		sb.append("|");
		sb.append(phone);
		sb.append("|");
		return sb.toString();
	}
}
